(function($){
	$.lvi = {};
	$.lvi.fn = {};
	var win = window,
		doc = window.document;
	function SiteCategoryNav(elem,config){
		var defConf = {
			
		};
		this.conf = $.extend({}, defConfig, config);
		this.element = $(elem);
		this._init();
	}
	SiteCategoryNav.prototype = {
		_init : function(){
			this.categories = $('.nav-cat-li',this.element);
			this.subcats = $('.nav-list div',this.element);
			this.panel = $('.nav-panel',this.element);
			
			this.isShow = false;
			this.timerId = -1;
		},
		_attachEvent : function(){
			self = this;
			this.categories.mouseleave(function(){
				self.isShow = false;
				self.hide();
			});
		},			
		hide : function(){
			self = this;
			highlight(-1);
			navPanel.animate(
			{
				width: '194'
			}, 300,null);
		}
	};
	var navCat = $('#category-nav'),
		navCatsList = $('#nav-cats .nav-cat-li'),
		navSubcatList = $('#nav_subcats div'),
		navPanel = $('#category-nav .nav-panel'),
		isShow = false,
		timerId = -1;
		
	navCat.mouseover(function() {
		
	}).mouseleave(function(){
		isShow = false;
		//timerId = win.setTimeout(function(){
			hide();
		//},1000);
	});
	
	function show(){
		/*if(timerId>0){
			win.clearTimeout(timerId);
			timerId = -1;
			return;
		}*/
		navPanel.animate({
			width: '350'
		}, 300, null);
	};
	function hide(){
		highlight(-1);
		navPanel.animate({
			width: '194'
		}, 300,null);
	}; 
	function highlight(index){
		navCatsList.each(function(tempIndex,tempItem){
			var oTempItem = $(tempItem);
			oTempItem.removeClass('nav-active');
			if(index == tempIndex){
				oTempItem.addClass('nav-active');
			}
		});
	};
	navCatsList.bind('mouseover',function(item){
		if(!isShow){
			show();
			isShow = true;
		}
		var index = item.target.id.replace('nav-cat-','');
		navSubcatList.each(function(subIndex,subItem){
			subItem.style.display = 'none';
			if('nav-subcats-'+index == subItem.id){
				subItem.style.display = 'block';
			}
		});
		highlight(index);
	});
})(jQuery);
